package push.tools.service.framework;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import push.tools.service.utils.crypto.CryptoUtils;
import push.tools.service.utils.crypto.SecretKeyPool;
import push.tools.service.utils.response.ResponseUtils;

public abstract class CryptoSupport {

    private static final Logger logger = LoggerFactory.getLogger(CryptoSupport.class);

    //秘钥
    private static final String secretKey = SecretKeyPool.keyMap.get("base_secret_key");

    //只要响应成功都加密返回
    protected static <T> String generateSucceed(T data) {
        String resp = ResponseUtils.generateSucceed(data);
        return CryptoUtils.encrypt(secretKey, resp);
    }

    //只要响应成功都加密返回
    protected static <T> String generateFail(String des) {
        String resp = ResponseUtils.generateFail(des);
        return CryptoUtils.encrypt(secretKey, resp);
    }

    //只要响应成功都加密返回
    protected static <T> String generateFailForCode(String code, String des) {
        String resp = ResponseUtils.generateFail(code, des);
        return CryptoUtils.encrypt(secretKey, resp);
    }

    //只要响应成功都加密返回
    protected static <T> String generateFailForCode(String code, String des, T data) {
        String resp = ResponseUtils.generateFail(code, des, data);
        return CryptoUtils.encrypt(secretKey, resp);
    }

    //解密数据
    protected static String decryptData(String content) {
        return CryptoUtils.decrypt(secretKey, content);
    }
}
